package com.example.rescuer.zyfypt_926wyr.activities;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.menu.ActionMenuItemView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import com.example.rescuer.zyfypt_926wyr.R;
import com.example.rescuer.zyfypt_926wyr.iface.CollectListener;
import com.example.rescuer.zyfypt_926wyr.model.CollectModel;


public class ViewVideoActivity extends AppCompatActivity {
    private VideoView videoView;
    private String path = "";
    private String BASEURL = "http://amicool.neusoft.edu.cn/";
    private ProgressDialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_video);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); //设置屏幕方向为横向
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置全屏

        getWindow().setFormat(PixelFormat.TRANSLUCENT);//透明
        videoView = (VideoView) findViewById(R.id.videoView2);

        path = BASEURL + "Uploads/video/video/" + getIntent().getStringExtra("videopath");//获取视频全路径?

        Uri uri = Uri.parse(path);
        videoView.setMediaController(new MediaController(this));//媒体播放控制工具
        videoView.setVideoURI(uri);
        videoView.setOnPreparedListener(new MyPlayerOnPreparedListener());//播放开始回调
        videoView.setOnCompletionListener(new MyPlayerOnCompletionListener());//播放完成回调
        videoView.requestFocus();//让videoview获取焦点
        videoView.start();


    }

    //自定义子类，监听视频准备好，消除加在对话框
    class MyPlayerOnPreparedListener implements MediaPlayer.OnPreparedListener {

        @Override
        public void onPrepared(MediaPlayer mp) {
            videoView.setBackgroundColor(Color.argb(0, 0, 255, 0));
        }
    }

    //自定义子类，监听播放完成，限时完成
    class MyPlayerOnCompletionListener implements MediaPlayer.OnCompletionListener {

        @Override
        public void onCompletion(MediaPlayer mp) {
            Toast.makeText(ViewVideoActivity.this, "播放完成", Toast.LENGTH_SHORT).show();

            //getSupportActionBar().show();
        }

    }
}







